package core.controller;

import core.pojo.StudentClass;
import core.pojo.StudentTemp;
import core.service.StudentAndClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StudentAndClassController {

    @Autowired
    private StudentAndClassService studentAndClassService;

    /**
     * 获取某学生以及该学生所在班级的信息
     *
     * @param id
     * @return
     */
    @RequestMapping("student/{id}")
    @ResponseBody
    public StudentTemp getStudentAndClass(@PathVariable int id) {
        StudentTemp st = studentAndClassService.getStudentAndClass(id);
        return st;
    }

    /**
     * 获取某学生以及该学生所在班级的信息
     *
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("studentclass/{id}")
    public StudentClass getStudentAndClassView(@PathVariable int id) {
        StudentClass sc = studentAndClassService.getStudentAndClassView(id);
        return sc;
    }

    /**
     * 获取某班级以及班级里面所有学生的信息
     *
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("class/{id}")
    public StudentTemp getClassStudents(@PathVariable int id) {

        StudentTemp st = studentAndClassService.getStudentAndClass(id);

        return st;
    }

    @RequestMapping("delete/{id}")
    @ResponseBody
    public String deleteClassStudent(@PathVariable int id) {

        studentAndClassService.deleteClassStudent(id);
        return "success";
    }

}
